package com.kotodama.infrastructure.config;

import com.kotodama.infrastructure.tenant.resolver.TenantResolver;
import com.kotodama.infrastructure.tenant.resolver.SubdomainTenantResolver;
import com.kotodama.infrastructure.tenant.resolver.header.HttpHeaderTenantResolver;
import com.kotodama.infrastructure.tenant.resolver.path.UrlPathTenantResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

import java.util.List;

/**
 * 租户解析器配置
 * 配置租户解析器的优先级和注入顺序
 */
@Configuration
public class TenantResolverConfig {

    /**
     * 子域名租户解析器
     * 优先级最高
     */
    @Bean
    @Order(1)
    public TenantResolver subdomainTenantResolver() {
        return new SubdomainTenantResolver();
    }

    /**
     * HTTP头租户解析器
     * 优先级中等
     */
    @Bean
    @Order(2)
    public TenantResolver httpHeaderTenantResolver() {
        return new HttpHeaderTenantResolver();
    }

    /**
     * URL路径租户解析器
     * 优先级最低
     */
    @Bean
    @Order(3)
    public TenantResolver urlPathTenantResolver() {
        return new UrlPathTenantResolver();
    }

    /**
     * 租户解析器列表
     * 按优先级排序
     */
    @Bean
    public List<TenantResolver> tenantResolvers(
            TenantResolver subdomainTenantResolver,
            TenantResolver httpHeaderTenantResolver,
            TenantResolver urlPathTenantResolver) {
        return List.of(
                subdomainTenantResolver,
                httpHeaderTenantResolver,
                urlPathTenantResolver);
    }
}